<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/6/4
 * Time: 14:49
 */

namespace app\admin\controller;


use app\admin\model\AdminList;
use app\admin\model\AssembleList;
use think\Controller;
use think\facade\Session;

class Login extends Controller
{

    public function login(){
        return $this->fetch();
    }

    public function doLogin(){
        $post = input('post.');
        $validate = $this->validate($post,'app\admin\validate\Login.login');
        if (true !== $validate){
            return json(['code'=>0,'msg'=>$validate]);
        }
        $admin = AdminList::where('username',$post['username'])->find();
        if (!$admin){
            return json(['code'=>0,'msg'=>'用户不存在']);
        }
        if (md5($post['username'].$post['password'].'adminFly') !== $admin['password']){
            return json(['code'=>0,'msg'=>'密码不正确']);
        }
        Session::set('admin_id',$admin['id']);
        Session::set('admin_name',$admin['username']);

        return json(['code'=>1,'msg'=>'登陆成功']);

    }

    public function loginOut(){
        Session::delete('admin_id');
        Session::delete('admin_name');
        return json(['code'=>1,'msg'=>'退出成功']);
    }


}